<template>
	<view>
		<view id="headslidewrap" class="headslidewrap">
			<view v-for="(v,i) in sortheadlist" :style="{transition:transitions,zIndex:sortheadlist.length-i}" class="headslideitem" :class="'headslideitem'+v.classtype">{{v.head}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[
					{
						head:'3535'
					},
					{
						head:'were'
					},
					{
						head:'dfgy'
					},
					{
						head:'dfgf'
					},
					{
						head:'eytf'
					},
					{
						head:'sdfs'
					},
				],
				sortheadlist:[],
				headnum:0,
				transitions:'300ms'
			}
		},
		methods: {
			setsortheadlist:function(){
				var self = this
				for(var i=0;i<this.list.length;i++){
					if(i<4){
						this.headnum = i
						this.sortheadlist.push({classtype:i+1,head:this.list[i].head})
					}
				}
				function fnback(){
					setTimeout(()=>{
						self.transitions = '800ms'
						for(var i=0;i<self.sortheadlist.length;i++){
							self.sortheadlist[i].classtype-=1
						}
						if(self.headnum<self.list.length - 1){
							self.headnum = self.headnum + 1							
						}else{
							self.headnum = 0
						}
						setTimeout(()=>{
							self.transitions = '0ms'
							self.sortheadlist.splice(0,1)
							self.sortheadlist.push({classtype:4,head:self.list[self.headnum].head})	
						},800)
						fnback()
					},2000)					
				}
				fnback()
			}
		},
		mounted(){
			this.setsortheadlist()				
		}
	}
</script>

<style scoped>
	.headslidewrap {
		position: relative;
		height: 80rpx;
		width: 220rpx;
	}
	.headslideitem {
		position: absolute;
		top: 0;
		width: 80rpx;
		height: 80rpx;
		background-color: #eee;
		border-radius: 50%;
		border: 1rpx solid #ccc;
	}
	.headslideitem0 {
		left: 52%;
		opacity: 0;
	}
	.headslideitem1 {
		left: 52%;
		opacity: 1;
	}
	.headslideitem2 {
		left: 26%;
		opacity: 1;
	}
	.headslideitem3 {
		left: 0%;
		opacity: 1;
	}
	.headslideitem4 {
		left: 0%;
		opacity: 0;
	}
</style>
